package com.android.common.base.rv;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.common.R;
import com.android.common.mvp.model.Node;


public class BaseTreeRvHolder<T> extends BaseRvHolder<Node<T>> {

    private final ImageView mIvExpandCollapse;

    private final TextView mTvName;

    public BaseTreeRvHolder(View itemView) {
        super(itemView);
        mIvExpandCollapse = itemView.findViewById(R.id.iv_expand_collapse);
        mTvName = itemView.findViewById(R.id.tv_name);
    }

    @Override
    public void bindData(Node<T> node, int position) {
        itemView.setPadding(node.getLevel() * 40, 8, 0, 8);
        mTvName.setText(node.getName());
        if (node.isLeaf()){
            mIvExpandCollapse.setVisibility(View.INVISIBLE);
        }else {
            mIvExpandCollapse.setVisibility(View.VISIBLE);
            mIvExpandCollapse.setImageResource(node.getIcon());
        }
    }
}
